﻿using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OnWork.DataCenter.BLL.Base.Dto;
using OnWork.DataCenter.BLL.DataCenter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnWork.DataCenter.Shared.Pages.DataStandard.Designer
{
    /// <summary>
    /// 标准选择列表
    /// </summary>
    public partial class StandardListDialog : ComponentBaseDataCenter, IResultDialog
    {

        /// <summary>
        /// 依赖注入 提示信息
        /// </summary>
        [Inject]
        protected DataStandardBLL dBConnBLL { get; set; }


        private Table<DataStandardConfigVO> table;

        /// <summary>
        /// 
        /// </summary>
        [Parameter]
        public EventCallback<List<DataStandardConfigVO>> ValueChanged { get; set; }


        public async Task<bool> OnClosing(DialogResult result)
        {
            if (result == DialogResult.Yes)
            {
                var rows = table.SelectedRows;
                if (rows == null || rows.Count == 0)
                {
                    await ToastService?.Error("错误", "请选择一条数据!");
                    return false;
                }
            }
            return true;
        }

        public async Task OnClose(DialogResult result)
        {
            if (result == DialogResult.Yes)
            {
                if (ValueChanged.HasDelegate)
                {
                    await ValueChanged.InvokeAsync(table.SelectedRows);
                }
            }
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private async Task<QueryData<DataStandardConfigVO>> QueryAsync(QueryPageOptions options)
        {
            var result = await dBConnBLL.QueryPagedListAsync(options.ToBaseQueryPageInput());
            //对象转换
            return result.ToQueryData<DataStandardConfigVO, OnWork.DataCenter.DAL.DataCenter.DataStandard>();
        }

        
    }
}
